package com.mcr.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mcr.reggie.common.R;
import com.mcr.reggie.entity.Category;
import com.mcr.reggie.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    /**
     *
     *
     * * * * * * * * * * * * * * * * * * * * *后台 * * * * * * * * * * * * * * * * * * * * *
     *
     *
     */
    @ApiOperation("新增菜品")
    @PostMapping
    public R<String> save(@RequestBody Category category){
        categoryService.save(category);
        return R.success("新增菜品成功");
    }
    @ApiOperation("分页查询菜品(管理员)")
    @GetMapping(value = "/page")
    public R<Page> page(int page,int pageSize){
        Page<Category> categoryPage=categoryService.getPage(page,pageSize);
        return R.success(categoryPage);
    }
    @ApiOperation(value = "根据id删除菜品")
    @DeleteMapping
    public R<String> delete(Long ids){
        categoryService.remove(ids);
        return R.success("删除成功");
    }
    @ApiOperation(value = "根据id修改菜品分类信息")
    @PutMapping
    public R<String> update(@RequestBody Category category){
        categoryService.updateById(category);
        return R.success("修改成功");
    }
    /**
     *
     *
     * * * * * * * * * * * * * * * * * * * * *前台 * * * * * * * * * * * * * * * * * * * * *
     *
     *
     */
    @ApiOperation(value = "用户查看商品分类列表")
    @GetMapping(value = "/list")
    public R<List<Category>> list(Category category){
        List<Category> categoryList=categoryService.getList();
        return R.success(categoryList);
    }
}
